class SessionsController < ApplicationController
  layout 'devise'

  def new
  end

  def create
    user = User.authenticate(params[:email], params[:password])
    if user
        session[:user_id] = user.id
        session[:user_type_id] = user.user_type_id
        session[:email] = user.email
        session[:first_name] = user.first_name
        redirect_to root_path
    else
      redirect_to url_for(:controller => "sessions", :action => "new"), :notice => "Can't log in!"
        flash.now.alert = "Invalid email or password"
    end
  end

  def destroy
    session[:userid] = nil
    session[:user_type_id] = nil
    session[:email] = nil
    session[:first_name] = nil
    redirect_to root_path
  end
end

